﻿package commands 
{
	import flash.utils.ByteArray;
	import commands.classesinfo.*;
	
	/**
	 * ...
	 * @author wwx
	 * 50000007 摊牌
	 */
	public class ShowDownCmd extends abCommand  
	{
		
		public function ShowDownCmd() //: abCommand(CommandType.CMD_TYPE_SHOWDOWN)  
		{
			super(CommandType(CommandType.CMD_TYPE_SHOWDOWN));
			showDowndsInfo = new Array();
		}
		
		public var msgSeq:int;//消息号
		public var errorNum:int;//错误号	
		
		public var deskId:int;//桌子id
		public var count:int;//
		public var showDowndsInfo:Array;
		
		public function convertToCmd(bytes:ByteArray, offset:int, len:int):int
		{
			var ret:int = -1;
			msgSeq = (int) (bytes[offset + 0]) + ((int(bytes[offset + 1])) << 8) + ((int(bytes[offset + 2])) << 16) + ((int(bytes[offset + 3])) << 24);
			offset += 4;
			errorNum = (int) (bytes[offset + 0]) + ((int(bytes[offset+1])) << 8) + ((int(bytes[offset+2])) << 16) + ((int(bytes[offset+3])) << 24);
			offset += 4;
			
			deskId = (int) (bytes[offset + 0]) + ((int(bytes[offset+1])) << 8) + ((int(bytes[offset+2])) << 16) + ((int(bytes[offset+3])) << 24);
			offset += 4;
			
			count = (int) (bytes[offset + 0]) + ((int(bytes[offset+1])) << 8) + ((int(bytes[offset+2])) << 16) + ((int(bytes[offset+3])) << 24);
			offset += 4;
			
			//showDowndsInfo = new Array();
			var showDowndInfo:ShowDownInfo = null;

			for (var i:int = 0; i < count; i++)
			{
				showDowndInfo = new ShowDownInfo();
				showDowndInfo.seatId = (int) (bytes[offset + 0]) + ((int(bytes[offset + 1])) << 8) + ((int(bytes[offset + 2])) << 16) + ((int(bytes[offset + 3])) << 24);
				offset += 4;
				showDowndInfo.playerId = (int) (bytes[offset + 0]) + ((int(bytes[offset + 1])) << 8) + ((int(bytes[offset + 2])) << 16) + ((int(bytes[offset + 3])) << 24);
				offset += 4;
				
				if(0 != showDowndInfo.playerId)
				{
					showDowndInfo.firstCard = new CardInfo();
					showDowndInfo.firstCard.colorOfCard = (int) (bytes[offset + 0]) + ((int(bytes[offset + 1])) << 8) + ((int(bytes[offset + 2])) << 16) + ((int(bytes[offset + 3])) << 24);
					offset += 4;
					showDowndInfo.firstCard.contentOfCard = (int) (bytes[offset + 0]) + ((int(bytes[offset + 1])) << 8) + ((int(bytes[offset + 2])) << 16) + ((int(bytes[offset + 3])) << 24);
					offset += 4;
					
					showDowndInfo.secondCard = new CardInfo();
					showDowndInfo.secondCard.colorOfCard = (int) (bytes[offset + 0]) + ((int(bytes[offset + 1])) << 8) + ((int(bytes[offset + 2])) << 16) + ((int(bytes[offset + 3])) << 24);
					offset += 4;
					showDowndInfo.secondCard.contentOfCard = (int) (bytes[offset + 0]) + ((int(bytes[offset + 1])) << 8) + ((int(bytes[offset + 2])) << 16) + ((int(bytes[offset + 3])) << 24);
					offset += 4;					
				}
				
				showDowndsInfo[i] = showDowndInfo;
			}
			return 0;
		}			
	}
	
}